package com.heimachefu.common;

import java.util.ArrayList;

/**
 * @author liuxingdong@heimachefu.com
 * @date 2019/7/23 17:11
 */
public class Result {
    private Integer code;
    private Object data;
    private String msg;
    private Object error;
    private static volatile Result result;

    public static Result getInstance() {
        if (result == null) {
            synchronized(Result.class) {
                if (result == null) {
                    result = new Result();
                }
            }
        }

        return result;
    }

    public Result() {
    }

    public Integer getCode() {
        return this.code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public Object getData() {
        return this.data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    public String getMsg() {
        return this.msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getError() {
        return this.error;
    }

    public void setError(Object error) {
        this.error = error;
    }

    public String toString() {
        if (this.data != null) {
            return this.data instanceof ArrayList ? String.format("Result{code:%s,data:%s,msg:%s}", this.code, this.data.toString(), this.msg) : String.format("Result{code:%s,data:%s,msg:%s}", this.code, this.data, this.msg);
        } else {
            return String.format("Result{code:%s,msg:%s}", this.code, this.msg);
        }
    }
}
